package com.myapp.mobilesafe.db.dao;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

/**
 * Created by lijie on 2016/5/3.
 */
public class AdressDao {
    private static final String PATH = "/data/data/com.myapp.mobilesafe.activity/files/address.db";
    public static String getAddress(String number){
        String address = "未知号码";
        SQLiteDatabase database = SQLiteDatabase.openDatabase(PATH, null,
                SQLiteDatabase.OPEN_READONLY);
        if (number.matches("^1[3-8]\\d{9}$")) {
            Cursor cursor = database
                    .rawQuery(
                            "select location from data2 where id=(select outkey from data1 where id=?)",
                            new String[] { number.substring(0, 7) });

            if (cursor.moveToFirst()) {
                address = cursor.getString(0);
            }

            cursor.close();
        }

        database.close();

        return address;
    }
}
